--【说明】
--所以此宏是陨石之后自动踩神木，标记键默认左边的alt
--0层勾玉G4电1-4秒黑人起手，满勾玉G3奥0-3黑人起手，5层以上勾玉G5冰3-火2陨石起手
--键位自己改
--此宏会自动保持勾玉，自动循环


DianKai = 4   --自行修改电元素黑人启动（替换为G键位数字即可）
YunKai = 5   --自行修改陨石启动（替换为G键位数字即可）
AoKai = 3    --自行修改奥元素黑人启动（替换为G键位数字即可）


AnJian = { "1", "2", "3", "4", "Left", "Right" }--技能栏按键设置
--技能从左往右顺序
hr = AnJian[3]--黑人技能栏位置
ylb = AnJian[2]--原力波技能栏位置
ys = AnJian[1]--陨石技能栏位置
hd = AnJian[4]--电甲技能栏位置
dx = AnJian[5]--电刑技能栏位置
yd = AnJian[6]--引导技能栏位置
qy = "E"--强制移动键位
FuZhu = "lctrl"  --自行修改辅助键（无需一键功能修改为"rshift"即可）

H = 96235
X0 = 32767
Y0 = 30700

EnablePrimaryMouseButtonEvents(true)

function JiNeng_Down(JiNeng)
    if JiNeng == "Left" then
        PressKey("Lshift")
        PressMouseButton(1)--点击左键
    elseif JiNeng == "Right" then
        PressMouseButton(3)--点击右键
    else
        PressKey(JiNeng)
    end
end

function JiNeng_Up(JiNeng)
    if JiNeng == "Left" then
        ReleaseMouseButton(1)--点击左键
        ReleaseKey("Lshift")
    elseif JiNeng == "Right" then
        ReleaseMouseButton(3)--点击右键
    else
        ReleaseKey(JiNeng)
    end
end


--电刑
function DianXing_Down()
    if IsKeyLockOn("capslock") then
        JiNeng_Down(dx)
    end
end

function DianXing_Up()
    JiNeng_Up(dx)
end

function DianXing(CiShu, XiuZheng)
    if IsKeyLockOn("capslock") and CiShu > 0 then
        DianXing_Down()
        while CiShu > 1
        do
            YanChi(17)
            CiShu = CiShu - 1
        end
        YanChi(17 + XiuZheng)
        DianXing_Up()
    end
end

--引导
function YinDao_Down()
    if IsKeyLockOn("capslock") then
        JiNeng_Down(yd)
    end
end

function YinDao_Up()
    JiNeng_Up(yd)
end

function YinDao(CiShu, XiuZheng)
    if IsKeyLockOn("capslock") and CiShu > 0 then
        YinDao_Down()
        while CiShu > 1
        do
            YanChi(17)
            CiShu = CiShu - 1
        end
        YanChi(17 + XiuZheng)
        YinDao_Up()
    end
end

--原力波
function YuanLiBo_Down()
    if IsKeyLockOn("capslock") then
        JiNeng_Down(ylb)
    end
end

function YuanLiBo_Up()
    JiNeng_Up(ylb)
end

function YuanLiBo(CiShu, XiuZheng)
    if IsKeyLockOn("capslock") and CiShu > 0 then
        while CiShu > 0
        do
            YuanLiBo_Down()
            YuanLiBo_Up()
            YanChi(34 + XiuZheng)
            CiShu = CiShu - 1
        end
    end
end

--陨石
function YunShi_Down()
    if IsKeyLockOn("capslock") then
        JiNeng_Down(ys)
    end
end

function YunShi_Up()
    JiNeng_Up(ys)
end

function YunShi(CiShu, XiuZheng)
    if IsKeyLockOn("capslock") and CiShu > 0 then
        YunShi_Down()
        YunShi_Up()
        YanChi(33 + XiuZheng)
    end
end

--黑洞
function HeiDong_Down()
    if IsKeyLockOn("capslock") then
        JiNeng_Down(hd)
    end
end

function HeiDong_Up()
    JiNeng_Up(hd)
end

function HeiDong(CiShu, XiuZheng)
    if IsKeyLockOn("capslock") and CiShu > 0 then
        HeiDong_Down()
        HeiDong_Up()
        YanChi(34 + XiuZheng)
    end
end


--黑人
function HeiRen_Down()
    if IsKeyLockOn("capslock") then
        JiNeng_Down(hr)
    end
end

function HeiRen_Up()
    JiNeng_Up(hr)
end

function HeiRen(CiShu, XiuZheng)
    if IsKeyLockOn("capslock") and CiShu > 0 then
        HeiRen_Down()
        HeiRen_Up()
        YanChi(20)
        YinDao_Up()
        ReleaseKey("Lshift")
        YanChi(30)
        ShanDian(23, 0)
        YanChi(XiuZheng)
    end
end

--闪电冲击
function ShanDian_Down()
    if IsKeyLockOn("capslock") then
        PressKey(AnJian[1])--点击1键
    end
end

function ShanDian_Up()
    ReleaseKey(AnJian[1])--释放1键
end

function ShanDian(CiShu, XiuZheng)
    if IsKeyLockOn("capslock") and CiShu > 0 then
        while CiShu > 0
        do
            if QiDong == 0 then
                YanChi(50)
            else
                ShanDian_Down()
                ShanDian_Up()
                YanChi(50)
            end
            CiShu = CiShu - 1
        end
    end
end

--延迟
function YanChi(ZhenShu)
    if IsKeyLockOn("capslock") then
        --判断是否灯亮
        XianZai = GetRunningTime() --得到延迟脚本开始时间
        while XianZai - KaiShi < (XianZai_ZhenShu + ZhenShu) / 60 * 1000 and IsKeyLockOn("capslock")
        do
            if (IsModifierPressed("lalt")) and BJ == 0 then
                --可以自行修改标记神目位置的按键
                ShenmuPosX, ShenmuPosY = GetMousePosition()
                BJ = 1
            end
            Sleep(3)
            XianZai = GetRunningTime() --得到延迟脚本过程的绝对时间
        end
        XianZai_ZhenShu = XianZai_ZhenShu + ZhenShu
    end
end

--分解
function FenJie()
    MoveMouseTo(32768 + (6000 - 32768), 17000)
    Sleep(100)
    PressAndReleaseMouseButton(1)
    Sleep(50)
    k = 0
    while k < 60
    do
        X = k % 10-- 分解列
        Y = math.floor(k / 10)--分解行
        MoveMouseTo(32768 + (49000 + 1700 * X - 32768), 36000 + 3000 * Y)
        Sleep(1)
        PressAndReleaseMouseButton(1)
        Sleep(1)
        PressAndReleaseKey("Enter")
        Sleep(1)
        PressAndReleaseMouseButton(1)
        Sleep(1)
        PressAndReleaseKey("Enter")
        Sleep(1)
        k = k + 1
    end
end

function Calculation()
    a1 = X0
    b1 = 2 * Y0 - H
    a2 = X0 + 0.3 * ((ShenmuPosX - X0) * H / (-2 * Y0 + H + ShenmuPosY))
    b2 = 2 * Y0
    c1 = X0
    d1 = Y0
    c2 = ShenmuPosX
    d2 = ShenmuPosY
    ShenmuPosX1 = math.floor(((a2 - a1) * (c2 - c1) * (d2 - b2) + (b2 - b1) * (c2 - c1) * a2 - (d2 - d1) * (a2 - a1) * c2) / ((b2 - b1) * (c2 - c1) - (d2 - d1) * (a2 - a1)))
    ShenmuPosY1 = math.floor((b2 - b1) / (a2 - a1) * (ShenmuPosX1 - a2) + b2)
    a3 = X0 + 0.7 * ((ShenmuPosX - X0) * H / (-2 * Y0 + H + ShenmuPosY))
    ShenmuPosX2 = math.floor(((a3 - a1) * (c2 - c1) * (d2 - b2) + (b2 - b1) * (c2 - c1) * a3 - (d2 - d1) * (a3 - a1) * c2) / ((b2 - b1) * (c2 - c1) - (d2 - d1) * (a3 - a1)))
    ShenmuPosY2 = math.floor((b2 - b1) / (a3 - a1) * (ShenmuPosX2 - a3) + b2)
    YunShiX = math.floor(X0 + (H + Y - Y0) * ((X0 - ShenmuPosX1) * H ^ 2 / (H + ShenmuPosY1 - Y0) ^ 2) / H + H * (X - X0) / (H + ShenmuPosY1 - Y0))
    YunShiY = math.floor(Y0 + (Y0 - ShenmuPosY1) * H / (H + ShenmuPosY1 - Y0) - (Y0 - Y) * H / (H + ShenmuPosY1 - Y0))
end

----------------------------------------------------主程序------------------------------------------------

function OnEvent(event, arg)
    if (event == "MOUSE_BUTTON_PRESSED" and arg == DianKai and not IsModifierPressed(FuZhu)) then
        CiShu = 0
        Sleep(200)
        KaiShi = GetRunningTime()
        XianZai_ZhenShu = 0
        while IsKeyLockOn("capslock")
        do
            HeiRen(1, 0)
            if CiShu == 0 then
                YanChi(5)
                YuanLiBo(6, 0)
                YanChi(5)
                CiShu = 1
            end
            YanChi(3)
            YinDao(1, 0)
            YuanLiBo(3, 0)
            BJ = 0
            ShenmuPosX = X0
            ShenmuPosY = Y0
            YanChi(15)
            YuanLiBo(1, 0)
            DianXing(6, -9)
            YunShi(1, 0)
            DianXing(2, 0)
            YanChi(5)
            YinDao(2, 0)--出神目
            DianXing(1, 0)
            YinDao(5, 0)
            YanChi(2)
            YuanLiBo(1, 0)
            DianXing(2, 0)
            X, Y = GetMousePosition()--记录陨石位置
            Calculation()
            if ShenmuPosX ~= X0 and ShenmuPosY ~= Y0 then
                MoveMouseTo(ShenmuPosX1, ShenmuPosY1)
                PressAndReleaseKey(qy)
            end
            YanChi(34)
            if ShenmuPosX ~= X0 and ShenmuPosY ~= Y0 then
                MoveMouseTo(YunShiX, YunShiY)
            end
            DianXing(4, 0)
            YunShi(1, -32)
            if ShenmuPosX ~= X0 and ShenmuPosY ~= Y0 then
                MoveMouseTo(ShenmuPosX2, ShenmuPosY2)
                PressAndReleaseKey(qy)
            end
            YanChi(60)
            MoveMouseTo(X0, Y0)
            YanChi(14)
            YinDao_Down()
            YanChi(1)
        end
        ReleaseKey("Lshift")
    end

    if (event == "MOUSE_BUTTON_PRESSED" and arg == AoKai and not IsModifierPressed(FuZhu)) then
        CiShu = 0
        Sleep(200)
        KaiShi = GetRunningTime()
        XianZai_ZhenShu = 0
        while IsKeyLockOn("capslock")
        do
            HeiRen(1, 0)
            if CiShu == 0 then
                YinDao(2, 0)
                CiShu = 1
            end
            YanChi(3)
            YinDao(1, 0)
            YuanLiBo(3, 0)
            BJ = 0
            ShenmuPosX = X0
            ShenmuPosY = Y0
            YanChi(15)
            YuanLiBo(1, 0)
            DianXing(6, -9)
            YunShi(1, 0)
            DianXing(2, 0)
            YanChi(5)
            YinDao(2, 0)--出神目
            DianXing(1, 0)
            YinDao(5, 0)
            YanChi(2)
            YuanLiBo(1, 0)
            DianXing(2, 0)
            X, Y = GetMousePosition()--记录陨石位置
            Calculation()
            if ShenmuPosX ~= X0 and ShenmuPosY ~= Y0 then
                MoveMouseTo(ShenmuPosX1, ShenmuPosY1)
                PressAndReleaseKey(qy)
            end
            YanChi(34)
            if ShenmuPosX ~= X0 and ShenmuPosY ~= Y0 then
                MoveMouseTo(YunShiX, YunShiY)
            end
            DianXing(4, 0)
            YunShi(1, -32)
            if ShenmuPosX ~= X0 and ShenmuPosY ~= Y0 then
                MoveMouseTo(ShenmuPosX2, ShenmuPosY2)
                PressAndReleaseKey(qy)
            end
            YanChi(60)
            MoveMouseTo(X0, Y0)
            YanChi(14)
            YinDao_Down()
            YanChi(1)
        end
        ReleaseKey("Lshift")
    end

    if (event == "MOUSE_BUTTON_PRESSED" and arg == YunKai and not IsModifierPressed(FuZhu)) then
        Sleep(200)
        KaiShi = GetRunningTime()
        XianZai_ZhenShu = 0
        while IsKeyLockOn("capslock")
        do
            BJ = 0
            ShenmuPosX = X0
            ShenmuPosY = Y0
            YanChi(15)
            YuanLiBo(1, 0)
            DianXing(6, -9)
            YunShi(1, 0)
            DianXing(2, 0)
            YanChi(5)
            YinDao(2, 0)--出神目
            DianXing(1, 0)
            YinDao(5, 0)
            YanChi(2)
            YuanLiBo(1, 0)
            DianXing(2, 0)
            X, Y = GetMousePosition()--记录陨石位置
            Calculation()
            if ShenmuPosX ~= X0 and ShenmuPosY ~= Y0 then
                MoveMouseTo(ShenmuPosX1, ShenmuPosY1)
                PressAndReleaseKey(qy)
            end
            YanChi(34)
            if ShenmuPosX ~= X0 and ShenmuPosY ~= Y0 then
                MoveMouseTo(YunShiX, YunShiY)
            end
            DianXing(4, 0)
            YunShi(1, -32)
            if ShenmuPosX ~= X0 and ShenmuPosY ~= Y0 then
                MoveMouseTo(ShenmuPosX2, ShenmuPosY2)
                PressAndReleaseKey(qy)
            end
            YanChi(60)
            MoveMouseTo(X0, Y0)
            YanChi(14)
            YinDao_Down()
            YanChi(1)
            HeiRen(1, 0)
            YanChi(3)
            YinDao(1, 0)
            YuanLiBo(3, 0)
        end
        ReleaseKey("Lshift")
    end
    if (event == "MOUSE_BUTTON_PRESSED" and arg == 2 and IsModifierPressed(FuZhu)) then
        --辅助键+右键赌博
        k = 50
        while k > 0
        do
            PressAndReleaseMouseButton(3)
            Sleep(5)
            k = k - 1
        end
    end
    if (event == "MOUSE_BUTTON_PRESSED" and arg == 4 and IsModifierPressed(FuZhu)) then
        --辅助键+G4键分解
        FenJie()
        if IsKeyLockOn("capslock") then
            ReleaseKey("capslock")
            PressAndReleaseKey("capslock")
        end
    end
    if (event == "MOUSE_BUTTON_PRESSED" and arg == 1 and IsModifierPressed(FuZhu)) then
        --辅助键+左键拾取
        k = 25
        while k > 0
        do
            PressAndReleaseMouseButton(1)
            Sleep(15)
            k = k - 1
        end
    end
end